<template>
  <!-- ----------------------商品品论------------------ -->
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="userId" label="用户ID" align="center" />
    <el-table-column prop="valueId" label="商品ID" align="center" />
    <el-table-column prop="star" label="打分" align="center" />
    <el-table-column prop="content" label="评论内容" align="center" />

    <el-table-column prop="picUrls" label="评论图片" align="center">
      <template #default="scope">
        <!-- ----------------评论图片--------------------- -->
        <div class="demo-image">
          <el-image
            v-for="(path, index) in scope.row.picUrls"
            :key="index"
            style="width: 100px; height: 100px"
            :src="path"
            fit="scale-down"
          />
        </div>
      </template>
    </el-table-column>

    <el-table-column prop="updateTime" label="时间" align="center" />
    <el-table-column prop="keywords" label="操作" align="center" width="180">
      <template #default="scope">
        <el-button type="primary" style="width: 56px; height: 28px"
          >编辑</el-button>
          
        <el-button type="danger" style="width: 56px; height: 28px"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { useStore } from "@/store/index.js";
import { onMounted, reactive, ref, watch, onUpdated, inject } from "vue";
import { shopComment } from "@/api/api.js";
import { toReactive } from "@vueuse/shared";
import { ElMessageBox } from "element-plus";
// const {userId,valueId,star,content,picUrls,updateTime}= res.data.data.list
const store = useStore();
let tableData = reactive([]);
onMounted(() => {
  shopComment(1).then((res) => {
    tableData.push(...res.data.data.list);
  });
});

// 监听 count 变化
store.$subscribe((a, state) => {
  //清空数组
  if (tableData) {
    tableData.splice(0, tableData.length);
  }
  shopList(state.count).then((res) => {
    tableData.push(...res.data.data.list);
  });
});
</script>

<style lang="scss">
.el-space__item {
  width: 100%;
}
</style>